package com.ruoyi.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CmContractTemplates;
import com.ruoyi.system.service.ICmContractTemplatesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同模板Controller
 * 
 * @author ruoyi
 * @date 2025-11-05
 */
@RestController
@RequestMapping("/system/templates")
public class CmContractTemplatesController extends BaseController
{
    @Autowired
    private ICmContractTemplatesService cmContractTemplatesService;

    /**
     * 查询合同模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:templates:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmContractTemplates cmContractTemplates)
    {
        startPage();
        List<CmContractTemplates> list = cmContractTemplatesService.selectCmContractTemplatesList(cmContractTemplates);
        return getDataTable(list);
    }

    /**
     * 导出合同模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:templates:export')")
    @Log(title = "合同模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmContractTemplates cmContractTemplates)
    {
        List<CmContractTemplates> list = cmContractTemplatesService.selectCmContractTemplatesList(cmContractTemplates);
        ExcelUtil<CmContractTemplates> util = new ExcelUtil<CmContractTemplates>(CmContractTemplates.class);
        util.exportExcel(response, list, "合同模板数据");
    }

    /**
     * 获取合同模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:templates:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(cmContractTemplatesService.selectCmContractTemplatesById(id));
    }

    /**
     * 新增合同模板
     */
    @PreAuthorize("@ss.hasPermi('system:templates:add')")
    @Log(title = "合同模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmContractTemplates cmContractTemplates)
    {
        return toAjax(cmContractTemplatesService.insertCmContractTemplates(cmContractTemplates));
    }

    /**
     * 修改合同模板
     */
    @PreAuthorize("@ss.hasPermi('system:templates:edit')")
    @Log(title = "合同模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmContractTemplates cmContractTemplates)
    {
        return toAjax(cmContractTemplatesService.updateCmContractTemplates(cmContractTemplates));
    }

    /**
     * 删除合同模板
     */
    @PreAuthorize("@ss.hasPermi('system:templates:remove')")
    @Log(title = "合同模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cmContractTemplatesService.deleteCmContractTemplatesByIds(ids));
    }
}
